
<template>
    <div>
        <Table border :columns="columns" :data="tableData"></Table>
        <!--删除弹窗-->
        <Modal v-model="removeModel" width="360">
            <p slot="header" style="color:#f60;">
                <Icon type="information-circled"></Icon>
                <span>删除提示</span>
            </p>
            <div style="text-align:center">
                <p style="font-size:18px;">数据删除后不可恢复，请谨慎操作！</p>
            </div>
            <div slot="footer">
                <Button type="error" @click="remove()" size="large">删除</Button>
                <Button type="info" @click="noRemove()" size="large">取消</Button>
            </div>
        </Modal>
        <!--绑定人员弹窗-->
        <Modal v-model="partyUserModel" width="720" :closable="true">
                <p slot="header" style="color:#f60;">
                    <Icon type="information-circled"></Icon>
                    <span>人员列表</span>
                </p>
                <Form label-position="left" :label-width="72">
                    <Row :gutter="15">
                        <i-col span="12">
                        <FormItem label="联系方式：">
                            <Input v-model="userPhone" placeholder="请输入联系方式"/>
                        </FormItem>
                        </i-col>
                        <i-col span="6">
                        <Button type="success" @click="searchData" icon="ios-search" >搜索</Button>
                        </i-col>
                    </Row>
                </Form>
                <div style='margin-top:20px;'>
                    <Table class='hide-header-checkbox' border :columns="user_columns" :data="user_data" @on-select="selectChange" @on-select-cancel = "cancelData"></Table>
                    <div style="height: auto;overflow:hidden">
                        <Page ref="pages" :total="itemTotal" :page-size="3" show-total style="float: right; margin-top: 20px;" @on-change="getList"></Page>
                    </div>
                </div>

                <div slot="footer">

                </div>
            </Modal>
    </div>
</template>

<script>
import ajax from '../../../../libs/axios.js'
export default {
    props: {
        tableData: Array,
        access: Object
    },
    data () {
        return {
            removeModel:false,         // 删除弹窗
            partyUserModel:false,      // 绑定人员弹窗
            partyId:"",                // 企业id
            userId:"",                 // 用户的id
            user_data: [],             // 企业下的用户
            itemTotal: 0,              // 目前在没有找到合适的获取数据总个数之前，先使用默认值数据
            userPhone:'',              // 用户手机号
            user_columns:[
                {
                    type: 'selection',
                    width: 60,
                    align: 'center'
                },
                {
                    title: '用户姓名',
                    align: 'center',
                    key: 'realName',
                },
                {
                    title: '联系方式',
                    align: 'center',
                    key: 'mobile'
                },
                {
                    title: '身份证号',
                    align: 'center',
                    key: 'cardNum'
                }
            ],
            columns: [
                {
                    title: '序号',
                    type: 'index',
                    width: 80,
                    align: 'center'
                },
                {
                    title: '企业名称',
                    align: 'center',
                    width: 280,
                    key: 'name'
                },
                {
                    title: '企业类型',
                    align: 'center',
                    width: 100,
                    key: 'partyType',
                    render: (h, params) => {
                        if (params.row.partyType === 1) {
                            return h('span', '2P')
                        } else if(params.row.partyType === 2) {
                            return h('span', '4S')
                        } else if(params.row.partyType === 3) {
                            return h('span', '监管店')
                        } else if(params.row.partyType === 4) {
                            return h('span', '2B')
                        } else if(params.row.partyType === 5) {
                            return h('span', '小b')
                        } else if(params.row.partyType === 6) {
                            return h('span', '个人')
                        } else {
                            return h('span', '其他')
                        }
                    }
                },
                {
                    title: '法人名称',
                    align: 'center',
                    width: 100,
                    key: 'legalPerson'
                },
                {
                    title: '法人身份证',
                    align: 'center',
                    width: 180,
                    key: 'legalCard'
                },
                {
                    title: '来源',
                    align: 'center',
                    width: 80,
                    key: 'dataSource',
                    render: (h, params) => {
                        if (params.row.dataSource === 1) {
                            return h('span', '前端')
                        }  else if(params.row.dataSource === 2) {
                            return h('span', '后台')
                        } else {
                            return h('span', '其他')
                        }
                    }
                },
                {
                    title: '状态',
                    align: 'center',
                    width: 100,
                    key: 'status',
                    render: (h, params) => {
                        if (params.row.status === 1) {
                            return h('span', '待审核')
                        }  else if(params.row.status === 2) {
                            return h('span', '审核成功')
                        }else if(params.row.status === 3) {
                            return h('span', '审核失败')
                        }else{
                            return h('span', '其他')
                        }
                    }
                },
                {
                    title: '创建时间',
                    align: 'center',
                    width: 180,
                    key: 'crtTime'
                },
                {
                    title: '操作',
                    key: 'action',
                    width: 240,
                    fixed: 'right',
                    align: 'center',
                    render: (h, params) => {
                        return h('div', [
                            h(
                                'Button',
                                {
                                    props: {
                                        type: 'primary',
                                        size: 'small'

                                    },
                                    style: {
                                        marginRight: '5px',
                                        display: params.row.partyType !== 4 && params.row.partyType !== 5 ? 'inline-block' : 'none'
                                    },
                                    on: {
                                        click: () => {
                                            this.infoData(params.row.id)
                                        }
                                    }
                                },
                                '详情'
                            ),
                            h(
                                'Button',
                                {
                                    props: {
                                        type: 'primary',
                                        size: 'small'

                                    },
                                    style: {
                                        marginRight: '5px',
                                        display: params.row.partyType === 4 ? 'inline-block' : 'none'
                                    },
                                    on: {
                                        click: () => {
                                            this.infoData1(params.row.id)
                                        }
                                    }
                                },
                                '详情'
                            ),
                            h(
                                'Button',
                                {
                                    props: {
                                        type: 'primary',
                                        size: 'small'

                                    },
                                    style: {
                                        marginRight: '5px',
                                        display: params.row.partyType === 5 ? 'inline-block' : 'none'
                                    },
                                    on: {
                                        click: () => {
                                            this.infoData2(params.row.id)
                                        }
                                    }
                                },
                                '详情'
                            ),
                            h(
                                'Button',
                                {
                                    props: {
                                        type: 'error',
                                        size: 'small'
                                    },
                                    style: {
                                        marginRight: '5px'
                                    },
                                    on: {
                                        click: () => {
                                            this.goRemove(params.index, params.row.id);

                                        }
                                    }
                                },
                                '删除'
                            ),
                            // h(
                            //     'Button',
                            //     {
                            //         props: {
                            //             type: 'info',
                            //             size: 'small'
                            //         },
                            //         style: {
                            //             marginRight: '5px',
                            //             display: this.access.func === true && params.row.status != 2 ? 'inline-block' : 'none'
                            //         },
                            //         on: {
                            //             click: () => {
                            //                  this.auditData(params.row.id,params.row.userId)
                            //             }
                            //         }
                            //     },
                            //     '审核'
                            // ),

                            h(
                                'Button',
                                {
                                    props: {
                                        type: 'success',
                                        size: 'small'
                                    },
                                    style: {
                                        marginRight: '5px',
                                        display: this.access.func === true? 'inline-block' : 'none'
                                    },
                                    on: {
                                        click: () => {
                                             this.editInfo(params.row.id)
                                        }
                                    }
                                },
                                '修改'
                            ),
                            h(
                                'Button',
                                {
                                    props: {
                                        type: 'warning',
                                        size: 'small'
                                    },
                                    style: {
                                        display: this.access.func === true? 'inline-block' : 'none'
                                    },
                                    on: {
                                        click: () => {
                                             this.salesmanSet(params.row.id,1)
                                        }
                                    }
                                },
                                '绑定人员'
                            ),

                        ])
                    }
                }
            ],
            data: []
        }
    },
    activated () {
        this.init()
    },
    methods: {
        // 数据初始化
        init () {},
        // 审核
        /*   auditData (id,userId) {
            let argu = {
                id: id,
                userId: userId
            }
            this.$router.push({
                name: 'auditPartyInfo',
                params: argu
            })
        },*/
        // 修改
        editInfo(id){
            let argu = {
                id: id
            }
            this.$router.push({
                name: 'editparty',
                params: argu

            })
        },
        // 详情
        infoData (id) {
            let argu = {
                id: id
            }
            this.$router.push({
                name: 'partyInfo',
                params: argu

            })
        },
        // 详情1
        infoData1 (id) {
            let argu = {
                id: id
            }
            this.$router.push({
                name: 'partyInfo_big_b',
                params: argu

            })
        },
        // 详情2
        infoData2 (id) {
            let argu = {
                id: id
            }
            this.$router.push({
                name: 'partyInfo_small_b',
                params: argu

            })
        },
        // 删除按钮
        goRemove (index, id) {
            this.modal = true
            this.id = id
            this.index = index
            this.removeModel = true
        },
        // 删除确定按钮
        remove () {
            let url = 'adminlogin/deleteCjParty'
            let data = {
                id: this.id
            }
            ajax
                .formRes(url, data)
                .then(res => {
                    if (res.data > 0) {
                        this.tableData.splice(this.index, 1)
                        this.removeModel = false
                    }
                })
                .catch(res => {
                    console.log('有错误信息')
                    // fail
                })
        },
        // 删除取消按钮
        noRemove () {
            this.removeModel = false
        },
        // 绑定人员
        salesmanSet(id,page){
            this.partyUserModel = true
            let _that = this
            _that.partyId = id
            _that.userId = window.localStorage.getItem('userId')
            //获取未绑定的数据信息
            let url = 'adminlogin/party/selectUserAll'
            let data = {
                pageSize:3,
                pageNum:page,
                partyId:id,
                mobile:_that.userPhone
            }
            ajax.formRes(url, data).then(res => {
                // success
                if(200 == res.code){
                    _that.user_data = res.data
                    _that.itemTotal = res.count;
                    _that.salesman = res.salesman
                    if(res.salesman != ""){
                       var arr =  res.salesman;
                       // 1、循环获取的数据
                        _that.user_data.forEach(item => {
                            // 2、循环选中的数据
                            for (let val of arr) {
                                // 3、比较数据，如果相等，则默认选中
                                if (item.id === val.business_MANAGER) {
                                    item._checked = true
                                }
                            }
                        })
                   }

                }else{
                    _that.$Message.success('数据原因，请联系管理员。')
                }

            }).catch(res => {
                console.log('有错误信息')
                // fail
            })
        },
        selectChange (seletion,row) {
            let _that = this
            let url = 'adminlogin/party/addSalesman'
            let data = {
                partyId:_that.partyId,
                manager:row.id,
                mobile:row.mobile,
                createUser:_that.userId
            }
            ajax.formRes(url, data).then(res => {
                if(200 == res.code){

                }else{
                    _that.$Message.success('数据原因，请联系管理员。')
                }
            }).catch(err => {
                console.log('有错误信息')
            })
        },
        cancelData(seletion,row){
            let _that = this
            let url = 'adminlogin/party/deleteSalesman'
            let data = {
                partyId:_that.partyId,
                manager:row.id
            }
            ajax.formRes(url, data).then(res => {
                // success
                if(200 == res.code){

                }else{
                    _that.$Message.success('数据原因，请联系管理员。')
                }

            }).catch(res => {
                console.log('有错误信息')
                // fail
            })

        },
        // 获取列表
        getList(page){
            this.partyId
            this.salesmanSet(this.partyId,page)
        },
        // 搜索
        searchData(){
           this.salesmanSet(this.partyId,1)
        },
        receiverData(){
            this.partyUserModel = false
        }
    },
}
</script>
<style>
    .hide-header-checkbox thead .ivu-checkbox-wrapper {
        display: none !important
    }
</style>
